
#include "CondMgr.h"

CondMgr::CondMgr() :m_pCondAPool(nullptr), m_pCondBPool(nullptr), m_pCondCPool(nullptr), m_pCondDPool(nullptr), m_pCondFPool(nullptr), m_pCondHPool(nullptr), m_pCondEmptyPool(nullptr)
{
	m_pCondGPool = nullptr;
	m_pCondIPool = nullptr;
}

CondMgr::~CondMgr()
{

}

bool CondMgr::Init()
{
	m_pCondAPool = new ObjectPool<CondA>(20, false);
	MMO_ASSERT(nullptr != m_pCondAPool);
	m_pCondBPool = new ObjectPool<CondB>(20, false);
	MMO_ASSERT(nullptr != m_pCondBPool);
	m_pCondCPool = new ObjectPool<CondC>(20, false);
	MMO_ASSERT(nullptr != m_pCondCPool);
	m_pCondDPool = new ObjectPool<CondD>(20, false);
	MMO_ASSERT(nullptr != m_pCondDPool);
	m_pCondEPool = new ObjectPool<CondE>(20, false);
	MMO_ASSERT(nullptr != m_pCondEPool);
	m_pCondEmptyPool = new ObjectPool<CondEmpty>(20, false);
	MMO_ASSERT(nullptr != m_pCondEmptyPool);
	m_pCondFPool = new ObjectPool<CondF>(20, false);
	MMO_ASSERT(nullptr != m_pCondFPool);
	m_pCondGPool = new ObjectPool<CondG>(20, false);
	MMO_ASSERT(nullptr != m_pCondGPool);
	m_pCondHPool = new ObjectPool<CondH>(20, false);
	MMO_ASSERT(nullptr != m_pCondHPool);
	m_pCondIPool = new ObjectPool<CondI>(20, false);
	MMO_ASSERT(nullptr != m_pCondIPool);
	


	return true;
}

void CondMgr::UnInit()
{
	MMO_DELETE(m_pCondAPool);
	MMO_DELETE(m_pCondBPool);
	MMO_DELETE(m_pCondCPool);
	MMO_DELETE(m_pCondDPool);
	MMO_DELETE(m_pCondEPool);
	MMO_DELETE(m_pCondEmptyPool);
	MMO_DELETE(m_pCondFPool);
	MMO_DELETE(m_pCondGPool);
	MMO_DELETE(m_pCondHPool);
	MMO_DELETE(m_pCondIPool);
	
}

ICond *CondMgr::MakeCondObj(int8_t byCondType)
{
	ICond *pcond = nullptr;
	switch (byCondType)
	{
	case (int8_t)EDupCondType::EDupCondType_Empty:
		{
			pcond = m_pCondEmptyPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_A:
		{
			pcond = m_pCondAPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_B:
		{
			pcond = m_pCondBPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_C:
		{
			pcond = m_pCondCPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_D:
		{
			pcond = m_pCondDPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_E:
		{
			pcond = m_pCondEPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_F:
		{
			pcond = m_pCondFPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_G:
		{
			pcond = m_pCondGPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_H:
		{
			pcond = m_pCondHPool->MallocObj();
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_I:
		{
			pcond = m_pCondIPool->MallocObj();
		}
		break;
	default:
		break;
	}

	return pcond;
}

void CondMgr::FreeCondObj(ICond *pCondObj)
{
	int8_t byCondType = pCondObj->getCondType();
	switch (byCondType)
	{
	case (int8_t)EDupCondType::EDupCondType_Empty:
		{
			m_pCondEmptyPool->FreeObj((CondEmpty*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_A:
		{
			m_pCondAPool->FreeObj((CondA*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_B:
		{
			m_pCondBPool->FreeObj((CondB*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_C:
		{
			m_pCondCPool->FreeObj((CondC*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_D:
		{
			m_pCondDPool->FreeObj((CondD*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_E:
		{
			m_pCondEPool->FreeObj((CondE*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_F:
		{
			m_pCondFPool->FreeObj((CondF*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_G:
		{
			m_pCondGPool->FreeObj((CondG*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_H:
		{
			m_pCondHPool->FreeObj((CondH*)pCondObj);
		}
		break;
	case (int8_t)EDupCondType::EDupCondType_I:
		{
			m_pCondIPool->FreeObj((CondI*)pCondObj);
		}
	break;
	default:
		{
			MMO_DELETE(pCondObj);
			LogErrFmtPrint("[logic] CondMgr::FreeCondObj....unkonwn cond type ....type:%d ", byCondType);
		}
		break;
	}
}

void CondMgr::RecycleCond(ICond *pCond)
{
	if (nullptr != pCond)
	{
		pCond->uninit();
		FreeCondObj(pCond);
	}
}